# -*- cmake -*-

FIND_PACKAGE(Lua REQUIRED)

INCLUDE_DIRECTORIES(${LUA_INCLUDE_DIR})

ADD_LIBRARY(luaT SHARED luaT.h luaT.c)
TARGET_LINK_LIBRARIES(luaT ${LUA_LIBRARIES})

INSTALL(TARGETS luaT
          RUNTIME DESTINATION "${Torch_INSTALL_BIN_SUBDIR}"
          LIBRARY DESTINATION "${Torch_INSTALL_LIB_SUBDIR}"
          ARCHIVE DESTINATION "${Torch_INSTALL_LIB_SUBDIR}")

INSTALL(FILES luaT.h
          DESTINATION "${Torch_INSTALL_INCLUDE_SUBDIR}")

# Create luaT.cmake
GET_TARGET_PROPERTY(LUAT_OUTPUT_NAME luaT LOCATION)
GET_FILENAME_COMPONENT(LUAT_OUTPUT_NAME ${LUAT_OUTPUT_NAME} NAME)
SET(LUAT_LIBRARIES "${Torch_INSTALL_LIB}/${LUAT_OUTPUT_NAME}")
SET(LUAT_INCLUDE_DIR "${Torch_INSTALL_INCLUDE}")
CONFIGURE_FILE(luaTConfig.cmake.in "${Torch_BINARY_DIR}/cmake-external/luaTConfig.cmake")
INSTALL(FILES "${Torch_BINARY_DIR}/cmake-external/luaTConfig.cmake" 
  DESTINATION "${Torch_INSTALL_CMAKE_SUBDIR}")

# luaT help
ADD_TORCH_HELP(luaT "Torch C Libraries")
